//本地缓存管理
class CacheManager {
    //存
    setCache(key: string, value: any) {
      //因为传进来的可能是对象, 使用json进行转换
      window.localStorage.setItem(key, JSON.stringify(value))
    }
    //取
    getCache(key: string) {
      const res = window.localStorage.getItem(key)
      if (res) {
        return JSON.parse(res)
      }
    }
    //删
    deleteCache(key: string) {
      window.localStorage.removeItem(key)
    }
    //删全部
    clearCache(key: string) {
      window.localStorage.clear()
    }
  }
  
  //export default cache: CacheManager = new CacheManager() 错误的,
  // 正确导出对象 export default new CacheManager()
  export default new CacheManager()
  